2020-2021 Sunseeker Telemetry and Lighting System
eusci_b_i2c.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // eusci_b_i2c.h - Driver for the EUSCI_B_I2C Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_EUSCI_B_I2C_H__
8 #define __MSP430WARE_EUSCI_B_I2C_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_EUSCI_Bx__
13 
14 //*****************************************************************************
15 //
16 // If building with a C++ compiler, make all of the definitions in this header
17 // have a C binding.
18 //
19 //*****************************************************************************
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include "inc/hw_memmap.h"
26 //*****************************************************************************
27 //
30 //
31 //*****************************************************************************
32 typedef struct EUSCI_B_I2C_initMasterParam {
38  uint8_t selectClockSource;
41  uint32_t i2cClk;
46  uint32_t dataRate;
48  uint8_t byteCounterThreshold;
54  uint8_t autoSTOPGeneration;
55 } EUSCI_B_I2C_initMasterParam;
56 
57 //*****************************************************************************
58 //
60 //
61 //*****************************************************************************
62 typedef struct EUSCI_B_I2C_initSlaveParam {
64  uint8_t slaveAddress;
71  uint8_t slaveAddressOffset;
76  uint32_t slaveOwnAddressEnable;
77 } EUSCI_B_I2C_initSlaveParam;
78 
79 
80 //*****************************************************************************
81 //
82 // The following are values that can be passed to the param parameter for
83 // functions: EUSCI_B_I2C_initMaster().
84 //
85 //*****************************************************************************
86 #define EUSCI_B_I2C_NO_AUTO_STOP UCASTP_0
87 #define EUSCI_B_I2C_SET_BYTECOUNT_THRESHOLD_FLAG UCASTP_1
88 #define EUSCI_B_I2C_SEND_STOP_AUTOMATICALLY_ON_BYTECOUNT_THRESHOLD UCASTP_2
89 
90 //*****************************************************************************
91 //
92 // The following are values that can be passed to the param parameter for
93 // functions: EUSCI_B_I2C_initMaster().
94 //
95 //*****************************************************************************
96 #define EUSCI_B_I2C_SET_DATA_RATE_400KBPS 400000
97 #define EUSCI_B_I2C_SET_DATA_RATE_100KBPS 100000
98 
99 //*****************************************************************************
100 //
101 // The following are values that can be passed to the param parameter for
102 // functions: EUSCI_B_I2C_initMaster().
103 //
104 //*****************************************************************************
105 #define EUSCI_B_I2C_CLOCKSOURCE_ACLK UCSSEL__ACLK
106 #define EUSCI_B_I2C_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
107 
108 //*****************************************************************************
109 //
110 // The following are values that can be passed to the param parameter for
111 // functions: EUSCI_B_I2C_initSlave().
112 //
113 //*****************************************************************************
114 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET0 0x00
115 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET1 0x02
116 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET2 0x04
117 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET3 0x06
118 
119 //*****************************************************************************
120 //
121 // The following are values that can be passed to the param parameter for
122 // functions: EUSCI_B_I2C_initSlave().
123 //
124 //*****************************************************************************
125 #define EUSCI_B_I2C_OWN_ADDRESS_DISABLE 0x00
126 #define EUSCI_B_I2C_OWN_ADDRESS_ENABLE UCOAEN
127 
128 //*****************************************************************************
129 //
130 // The following are values that can be passed to the mode parameter for
131 // functions: EUSCI_B_I2C_setMode() as well as returned by the
132 // EUSCI_B_I2C_getMode() function.
133 //
134 //*****************************************************************************
135 #define EUSCI_B_I2C_TRANSMIT_MODE UCTR
136 #define EUSCI_B_I2C_RECEIVE_MODE 0x0000
137 
138 //*****************************************************************************
139 //
140 // The following are values that can be passed to the mask parameter for
141 // functions: EUSCI_B_I2C_enableInterrupt(), EUSCI_B_I2C_disableInterrupt(),
142 // EUSCI_B_I2C_clearInterrupt(), and EUSCI_B_I2C_getInterruptStatus() as well
143 // as returned by the EUSCI_B_I2C_getInterruptStatus() function.
144 //
145 //*****************************************************************************
146 #define EUSCI_B_I2C_NAK_INTERRUPT UCNACKIE
147 #define EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT UCALIE
148 #define EUSCI_B_I2C_STOP_INTERRUPT UCSTPIE
149 #define EUSCI_B_I2C_START_INTERRUPT UCSTTIE
150 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT0 UCTXIE0
151 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT1 UCTXIE1
152 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT2 UCTXIE2
153 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT3 UCTXIE3
154 #define EUSCI_B_I2C_RECEIVE_INTERRUPT0 UCRXIE0
155 #define EUSCI_B_I2C_RECEIVE_INTERRUPT1 UCRXIE1
156 #define EUSCI_B_I2C_RECEIVE_INTERRUPT2 UCRXIE2
157 #define EUSCI_B_I2C_RECEIVE_INTERRUPT3 UCRXIE3
158 #define EUSCI_B_I2C_BIT9_POSITION_INTERRUPT UCBIT9IE
159 #define EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT UCCLTOIE
160 #define EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT UCBCNTIE
161 
162 //*****************************************************************************
163 //
164 // The following are values that can be passed toThe following are values that
165 // can be returned by the EUSCI_B_I2C_isBusBusy() function.
166 //
167 //*****************************************************************************
168 #define EUSCI_B_I2C_BUS_BUSY UCBBUSY
169 #define EUSCI_B_I2C_BUS_NOT_BUSY 0x00
170 
171 //*****************************************************************************
172 //
173 // The following are values that can be passed toThe following are values that
174 // can be returned by the EUSCI_B_I2C_masterIsStopSent() function.
175 //
176 //*****************************************************************************
177 #define EUSCI_B_I2C_STOP_SEND_COMPLETE 0x00
178 #define EUSCI_B_I2C_SENDING_STOP UCTXSTP
179 
180 //*****************************************************************************
181 //
182 // The following are values that can be passed toThe following are values that
183 // can be returned by the EUSCI_B_I2C_masterIsStartSent() function.
184 //
185 //*****************************************************************************
186 #define EUSCI_B_I2C_START_SEND_COMPLETE 0x00
187 #define EUSCI_B_I2C_SENDING_START UCTXSTT
188 
189 //*****************************************************************************
190 //
191 // The following are values that can be passed to the timeout parameter for
192 // functions: EUSCI_B_I2C_setTimeout().
193 //
194 //*****************************************************************************
195 #define EUSCI_B_I2C_TIMEOUT_DISABLE UCCLTO_0
196 #define EUSCI_B_I2C_TIMEOUT_28_MS UCCLTO_1
197 #define EUSCI_B_I2C_TIMEOUT_31_MS UCCLTO_2
198 #define EUSCI_B_I2C_TIMEOUT_34_MS UCCLTO_3
199 
200 //*****************************************************************************
201 //
202 // Prototypes for the APIs.
203 //
204 //*****************************************************************************
205 
206 //*****************************************************************************
207 //
219 //
220 //*****************************************************************************
221 extern void EUSCI_B_I2C_initMaster(uint16_t baseAddress,
222  EUSCI_B_I2C_initMasterParam *param);
223 
224 //*****************************************************************************
225 //
237 //
238 //*****************************************************************************
239 extern void EUSCI_B_I2C_initSlave(uint16_t baseAddress,
240  EUSCI_B_I2C_initSlaveParam *param);
241 
242 //*****************************************************************************
243 //
253 //
254 //*****************************************************************************
255 extern void EUSCI_B_I2C_enable(uint16_t baseAddress);
256 
257 //*****************************************************************************
258 //
268 //
269 //*****************************************************************************
270 extern void EUSCI_B_I2C_disable(uint16_t baseAddress);
271 
272 //*****************************************************************************
273 //
285 //
286 //*****************************************************************************
287 extern void EUSCI_B_I2C_setSlaveAddress(uint16_t baseAddress,
288  uint8_t slaveAddress);
289 
290 //*****************************************************************************
291 //
307 //
308 //*****************************************************************************
309 extern void EUSCI_B_I2C_setMode(uint16_t baseAddress,
310  uint16_t mode);
311 
312 //*****************************************************************************
313 //
326 //
327 //*****************************************************************************
328 extern uint8_t EUSCI_B_I2C_getMode(uint16_t baseAddress);
329 
330 //*****************************************************************************
331 //
343 //
344 //*****************************************************************************
345 extern void EUSCI_B_I2C_slavePutData(uint16_t baseAddress,
346  uint8_t transmitData);
347 
348 //*****************************************************************************
349 //
358 //
359 //*****************************************************************************
360 extern uint8_t EUSCI_B_I2C_slaveGetData(uint16_t baseAddress);
361 
362 //*****************************************************************************
363 //
376 //
377 //*****************************************************************************
378 extern uint16_t EUSCI_B_I2C_isBusBusy(uint16_t baseAddress);
379 
380 //*****************************************************************************
381 //
393 //
394 //*****************************************************************************
395 extern uint16_t EUSCI_B_I2C_masterIsStopSent(uint16_t baseAddress);
396 
397 //*****************************************************************************
398 //
410 //
411 //*****************************************************************************
412 extern uint16_t EUSCI_B_I2C_masterIsStartSent(uint16_t baseAddress);
413 
414 //*****************************************************************************
415 //
447 //
448 //*****************************************************************************
449 extern void EUSCI_B_I2C_enableInterrupt(uint16_t baseAddress,
450  uint16_t mask);
451 
452 //*****************************************************************************
453 //
485 //
486 //*****************************************************************************
487 extern void EUSCI_B_I2C_disableInterrupt(uint16_t baseAddress,
488  uint16_t mask);
489 
490 //*****************************************************************************
491 //
523 //
524 //*****************************************************************************
525 extern void EUSCI_B_I2C_clearInterrupt(uint16_t baseAddress,
526  uint16_t mask);
527 
528 //*****************************************************************************
529 //
577 //
578 //*****************************************************************************
579 extern uint16_t EUSCI_B_I2C_getInterruptStatus(uint16_t baseAddress,
580  uint16_t mask);
581 
582 //*****************************************************************************
583 //
597 //
598 //*****************************************************************************
599 extern void EUSCI_B_I2C_masterSendSingleByte(uint16_t baseAddress,
600  uint8_t txData);
601 
602 //*****************************************************************************
603 //
616 //
617 //*****************************************************************************
618 extern uint8_t EUSCI_B_I2C_masterReceiveSingleByte(uint16_t baseAddress);
619 
620 //*****************************************************************************
621 //
636 //
637 //*****************************************************************************
638 extern bool EUSCI_B_I2C_masterSendSingleByteWithTimeout(uint16_t baseAddress,
639  uint8_t txData,
640  uint32_t timeout);
641 
642 //*****************************************************************************
643 //
656 //
657 //*****************************************************************************
658 extern void EUSCI_B_I2C_masterSendMultiByteStart(uint16_t baseAddress,
659  uint8_t txData);
660 
661 //*****************************************************************************
662 //
676 //
677 //*****************************************************************************
678 extern bool EUSCI_B_I2C_masterSendMultiByteStartWithTimeout(uint16_t baseAddress,
679  uint8_t txData,
680  uint32_t timeout);
681 
682 //*****************************************************************************
683 //
696 //
697 //*****************************************************************************
698 extern void EUSCI_B_I2C_masterSendMultiByteNext(uint16_t baseAddress,
699  uint8_t txData);
700 
701 //*****************************************************************************
702 //
716 //
717 //*****************************************************************************
718 extern bool EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(uint16_t baseAddress,
719  uint8_t txData,
720  uint32_t timeout);
721 
722 //*****************************************************************************
723 //
737 //
738 //*****************************************************************************
739 extern void EUSCI_B_I2C_masterSendMultiByteFinish(uint16_t baseAddress,
740  uint8_t txData);
741 
742 //*****************************************************************************
743 //
758 //
759 //*****************************************************************************
760 extern bool EUSCI_B_I2C_masterSendMultiByteFinishWithTimeout(uint16_t baseAddress,
761  uint8_t txData,
762  uint32_t timeout);
763 
764 //*****************************************************************************
765 //
775 //
776 //*****************************************************************************
777 extern void EUSCI_B_I2C_masterSendStart(uint16_t baseAddress);
778 
779 //*****************************************************************************
780 //
793 //
794 //*****************************************************************************
795 extern void EUSCI_B_I2C_masterSendMultiByteStop(uint16_t baseAddress);
796 
797 //*****************************************************************************
798 //
812 //
813 //*****************************************************************************
814 extern bool EUSCI_B_I2C_masterSendMultiByteStopWithTimeout(uint16_t baseAddress,
815  uint32_t timeout);
816 
817 //*****************************************************************************
818 //
829 //
830 //*****************************************************************************
831 extern void EUSCI_B_I2C_masterReceiveStart(uint16_t baseAddress);
832 
833 //*****************************************************************************
834 //
843 //
844 //*****************************************************************************
845 extern uint8_t EUSCI_B_I2C_masterReceiveMultiByteNext(uint16_t baseAddress);
846 
847 //*****************************************************************************
848 //
860 //
861 //*****************************************************************************
862 extern uint8_t EUSCI_B_I2C_masterReceiveMultiByteFinish(uint16_t baseAddress);
863 
864 //*****************************************************************************
865 //
880 //
881 //*****************************************************************************
882 extern bool EUSCI_B_I2C_masterReceiveMultiByteFinishWithTimeout(uint16_t baseAddress,
883  uint8_t *txData,
884  uint32_t timeout);
885 
886 //*****************************************************************************
887 //
898 //
899 //*****************************************************************************
900 extern void EUSCI_B_I2C_masterReceiveMultiByteStop(uint16_t baseAddress);
901 
902 //*****************************************************************************
903 //
914 //
915 //*****************************************************************************
916 extern void EUSCI_B_I2C_enableMultiMasterMode(uint16_t baseAddress);
917 
918 //*****************************************************************************
919 //
930 //
931 //*****************************************************************************
932 extern void EUSCI_B_I2C_disableMultiMasterMode(uint16_t baseAddress);
933 
934 //*****************************************************************************
935 //
944 //
945 //*****************************************************************************
946 extern uint8_t EUSCI_B_I2C_masterReceiveSingle(uint16_t baseAddress);
947 
948 //*****************************************************************************
949 //
958 //
959 //*****************************************************************************
960 extern uint32_t EUSCI_B_I2C_getReceiveBufferAddress(uint16_t baseAddress);
961 
962 //*****************************************************************************
963 //
972 //
973 //*****************************************************************************
974 extern uint32_t EUSCI_B_I2C_getTransmitBufferAddress(uint16_t baseAddress);
975 
976 //*****************************************************************************
977 //
1001 //
1002 //*****************************************************************************
1003 extern void EUSCI_B_I2C_setTimeout(uint16_t baseAddress,
1004  uint16_t timeout);
1005 
1006 //*****************************************************************************
1007 //
1008 // Mark the end of the C bindings section for C++ compilers.
1009 //
1010 //*****************************************************************************
1011 #ifdef __cplusplus
1012 }
1013 #endif
1014 
1015 #endif
1016 #endif // __MSP430WARE_EUSCI_B_I2C_H__
uint8_t transmitData
MPU_initThreeSegmentsParam param